﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Prsrp
{
    /// <summary>
    /// Basic keyboard manager
    /// </summary>
    public class KeyboardManager
    {
        private static KeyboardState mpOldKeyboardState;
        private static KeyboardState mpCurKeyboardState;

        /// <summary>
        /// Basic Update function.
        /// </summary>
        public static void UpdateKeyboardState()
        {
            mpOldKeyboardState = mpCurKeyboardState;
            mpCurKeyboardState = Keyboard.GetState();
        }

        /// <summary>
        /// Return true if keys <typeparamref name="_pKey"/> is down in current keyboard state.
        /// </summary>
        public static bool IsKeyDown(Keys _pKey)
        {
            return mpCurKeyboardState.IsKeyDown(_pKey);
        }

        /// <summary>
        /// Return true if keys <typeparamref name="_pKey"/> is up in current keyboard state.
        /// </summary>
        public static bool IsKeyUp(Keys _pKey)
        {
            return mpCurKeyboardState.IsKeyUp(_pKey);
        }

        /// <summary>
        /// Return true if keys <typeparamref name="_pKey"/> is up in previous keyboard state.
        /// </summary>
        public static bool IsOldKeyDOwn(Keys _pKey)
        {
            return mpOldKeyboardState.IsKeyDown(_pKey);
        }

        /// <summary>
        /// Return true if keys <typeparamref name="_pKey"/> is down in previous keyboard state.
        /// </summary>
        public static bool IsOldKeyUp(Keys _pKey)
        {
            return mpOldKeyboardState.IsKeyUp(_pKey);
        }

        /// <summary>
        /// Return true if <paramref name="_pKey"/> is pressed only on the current frame.
        /// </summary>
        public static bool IsKeyPressedOnce(Keys _pKey)
        {
            return (mpCurKeyboardState.IsKeyDown(_pKey) && mpOldKeyboardState.IsKeyUp(_pKey));
        }
    }
}